package com.zyy;

import java.util.Stack;

/**
 * @author zyy
 * @date 2021/5/12 下午3:21
 * @description
 * 思路：两个栈操作
 * 从一个栈中push 从另外一个栈中pop
 */
public class Stack2Queue {

    Stack stack1 = new Stack();
    Stack stack2 = new Stack();

    public synchronized void put(Object o){
        stack1.push(o);
    }

    public synchronized Object pop(){
        if(stack1.isEmpty() && stack2.isEmpty()){
            return null;
        }

        if(stack2.isEmpty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }

        return stack2.pop();
    }

}
